#include "../source/db.hpp"
#include "../source/json_util.hpp"
#include <iostream>

using namespace Util;
using std::cout;
using std::endl;

void test_db(std::string username, std::string passwd)
{
    users_table ut(username, passwd);
    // Json::Value user;
    // user["username"] = "张五";
    // user["password"] = "123321";
    // user["email"] = Json::Value::null;
    // ut.insert(user);

    Json::Value login_user;
    // // ut.select_by_id(5, user_record);
    // ut.select_by_name("张五", user_record);

    // cout << user_record["user_id"].asUInt() << endl;
    
    // std::string res;
    // json::serialize(user_record, &res);

    // cout << res << endl;

    // ut.win(user_record["user_id"].asUInt());
    login_user["user_id"] = 1;
    login_user["password"] = "123321";
    if (!ut.login(login_user))
    {
        LOG(DEBUG, "login error");
    }
    else 
    {
        LOG(DEBUG, "login success");
    }

}

int main(int argc, char* argv[])
{
    if (argc != 3)
    {
        std::cout << "./db user passwd" << std::endl;
        return -1;
    }

    test_db(argv[1], argv[2]);

    return 0;
}